package com.pdsu.graduation_design.listener;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.pdsu.graduation_design.domain.Commodity;
import com.pdsu.graduation_design.domain.CommodityType;
import com.pdsu.graduation_design.utils.JsonUtil;
import com.pdsu.graduation_design.views.MainGridViewItemDetailActivity;

import java.util.List;

public class MainGridViewOnItemClickListener implements AdapterView.OnItemClickListener {

    /**
     * 传入数据
     * @param parent
     * @param view
     * @param position
     * @param id
     */

    List<CommodityType> commodityTypes;
    private Context context;

    public MainGridViewOnItemClickListener(Context context,List<CommodityType> commodityTypes) {
        this.commodityTypes = commodityTypes;
        this.context = context;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


        //点击启动activity进入相同type类型


        try {
            String commodityTypes_json = JsonUtil.ListToJson(commodityTypes);
            Intent intent=new Intent(context, MainGridViewItemDetailActivity.class);
            intent.putExtra("commodityTypesjson",commodityTypes_json);
            intent.putExtra("index",position);
            context.startActivity(intent);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }




    }
}
